package com.gaga.common.enums;


import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;

public enum ChartType {
    CARD(1, "卡片"),
    CHART(3, "图表"),
    TABLE(4, "表格"),
    COMBINER(5, "组合器");

    private final Integer code;
    private final String info;

    ChartType(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public Integer getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }

    public static ChartType getChartType(Integer code) {
        AtomicReference<ChartType> type = new AtomicReference<>();
        Arrays.stream(ChartType.values()).forEach(e -> {
            if (e.getCode() == code) {
                type.set(e);
            }
        });

        if (type.get() == null) {
            throw new RuntimeException( "ChartType不存在");
        }
        return type.get();
    }
}
